/**
 * 车辆信息初始化
 */
var shortTemplate = {
    id: "shortTemplateTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};


shortTemplate.showErrInfo = function(){
	Feng.error("文件不存在!");
}
/**
 * 初始化表格的列
 */
shortTemplate.initColumn = function () {
    return [
        {field: 'selectItem', checkbox: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '短信模板编码', field: 'templateCode', align: 'center', valign: 'middle', sortable: true},
        {title: '模板类型', field: 'templateName', align: 'center', valign: 'middle', sortable: true},
        {title: '模板内容', field: 'templateContent', align: 'center', valign: 'middle', sortable: true},
        {title: '模板状态', field: 'templateStatus', align: 'center', valign: 'middle', sortable: true,
        	formatter : function(value, row,index) {
        		if(value == 0){
        			return "审核中";
        		}else if(value == 1){
        			return "审核通过";
        		}else if(value == 1){
        			return "审核失败";
        		}
            }
        }
        	
        ];
};
shortTemplate.sx=function(){
	var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/base/shortTemplate/sx", function (data) {
        	if(data.resultCode==0){
        		Feng.success("同步成功!");
                shortTemplate.table.refresh();
        	}else{
        		Feng.error(data.msg + "!");
        	}
            
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    };

    Feng.confirm("确定同步短信模板?", operation);
}
/**
 * 检查是否选中
 */
shortTemplate.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        shortTemplate.seItem = selected;
        return true;
    }
};

shortTemplate.singleCheck = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
    	if(selected.length > 1){
    		Feng.info("请选择表格中的一条记录进行操作！");
            return false;
    	}else{
    		shortTemplate.seItem = selected[0];
            return true;
    	}
        
    }
};

//批量生成二维码
shortTemplate.openAddshortTemplates = function(){
	var index = layer.open({
        type: 2,
        title: '创建二维码',
        area: ['80%', '30%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/base/shortTemplate/toAdd'
    });
    this.layerIndex = index;
}



shortTemplate.openCodeView = function(){
	if (this.singleCheck()) {
        var index = layer.open({
            type: 2,
            title: '查看二维码',
            area: ['80%', '80%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/base/shortTemplate/toView/' + shortTemplate.seItem.id
        });
        this.layerIndex = index;
    }
}

shortTemplate.openshortTemplatePrint = function(){
	if (this.check()) {
		var selectedItems = shortTemplate.seItem;
    	
    	var ids = "";
    	for(var i=0;i<selectedItems.length;i++){
    		var selectedItem = selectedItems[i];
    		if(i<selectedItems.length - 1){
    			ids = ids+selectedItem.id + "," ;
    		}else{
    			ids = ids+selectedItem.id;
    		}
    	}
		
		var index = layer.open({
            type: 2,
            title: '打印二维码',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/base/shortTemplate/toPrint?ids=' + ids
        });
        this.layerIndex = index;
    }
}

/**
 * 删除
 */
shortTemplate.delete = function () {
    if (this.check()) {

    	var selectedItems = shortTemplate.seItem;
    	
    	var ids = "";
    	var names = "";
    	for(var i=0;i<selectedItems.length;i++){
    		var selectedItem = selectedItems[i];
    		if(i<selectedItems.length - 1){
    			ids = ids+selectedItem.id + "," ;
    			names = names+selectedItem.file_name +",";
    		}else{
    			ids = ids+selectedItem.id;
    			names = names+selectedItem.file_name;
    		}
    	}
    	
    	
        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/file/del", function (data) {
            	if(data.resultCode==0){
            		Feng.success("删除成功!");
                    shortTemplate.table.refresh();
            	}else{
            		Feng.error(data.msg + "!");
            	}
                
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("ids", ids);
            ajax.start();
        };

        Feng.confirm("是否刪除[" + names + "]?", operation);
    }
};



/**
 * 重置
 */
shortTemplate.resetSearch = function () {
    $("#condition").val("");
    shortTemplate.table.refresh();
};

/**
 * 查询字典列表
 */
shortTemplate.search = function () {
	var queryData = {};
    
    //shortTemplate.table.refreshOptions({pageNumber:1});
    shortTemplate.table.refresh({query: queryData});
};

$(function () {
	shortTemplate.init(); 
});

shortTemplate.init = function(){
	var defaultColunms = shortTemplate.initColumn();
	var paramsId =[
		];
    var table = new BSTable(shortTemplate.id, "/base/shortTemplate/list", defaultColunms,paramsId);
    table.setPaginationType("server");
    shortTemplate.table = table.init();
}

shortTemplate.close = function () {
    parent.layer.close(window.parent.shortTemplate.layerIndex);
};


